//
//  LXCarSellBaseViewController.m
//  LiXingZuLin
//
//  Created by ypj on 2022/1/5.
//

#import "LXCarSellBaseViewController.h"
#import "LXCarSellListViewController.h"
#import "YJPageControlView.h"
#import "LXTopSearchView.h"
#import "LXCarAddViewController.h"
#import "LXCarSearchViewController.h"
@interface LXCarSellBaseViewController ()<YJPageControlViewDelegate>
@property(nonatomic,strong)NSMutableArray   *   titleViewArray;
@property (nonatomic,strong)YJPageControlView *  PageControlView;
@property(nonatomic,strong) NSMutableArray    *  viewControllers;
@property(nonatomic) LXTopSearchView *searchView;
@end

@implementation LXCarSellBaseViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad {
   [super viewDidLoad];
    
    self.view.backgroundColor = ColorWithF5F5F5;
    
    [self layoutCustomNav:self.view title:@"出售管理"];
    
    LXTopSearchView *searchView = [[LXTopSearchView alloc] initWithFrame:CGRectMake(0,kViewTopHeight, kScreenWidth, 70)];
    searchView.textField.placeholder = @"输入车牌号/负责人查询";
    searchView.textField.width = searchView.width - 120;
    searchView.searchBtn.frame = CGRectMake(MaxX(searchView.textField)+15, searchView.textField.top, kScreenWidth-MaxX(searchView.textField)-30, searchView.textField.height);
    [searchView.searchBtn setBackgroundColor:mainColor];
    searchView.searchBtn.layer.cornerRadius = 3;
    searchView.searchBtn.layer.masksToBounds = YES;
    self.searchView = searchView;
    [searchView.searchBtn setTitle:@"新 增" forState:UIControlStateNormal];
    [searchView.searchBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [self.view addSubview:searchView];
    // 输入
    [searchView setChangeTextFieldBlock:^(NSString * _Nonnull text) {
        [kNotifyCenter postNotificationName:@"carSearchText" object:text];
    }];
    
    /**
     [searchView.textField whenTapped:^{
         LXCarSearchViewController *vc = [[LXCarSearchViewController alloc] init];
         [self pushToNextController:vc];
     }];
     */
    // 点击
    [searchView setClickBtnBlock:^(NSString * _Nonnull text) {
        LXCarAddViewController *vc = [[LXCarAddViewController alloc] init];
        [self pushToNextController:vc];
        
    }];
    
    self.titleViewArray = [NSMutableArray arrayWithArray:@[@"全部",@"已出售",@"出售中",@"未出售"]];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    self.viewControllers = [NSMutableArray array];
    CGRect frame = CGRectMake(0, MaxY(searchView), ScreenWidth, kScreenHeight - MaxY(searchView));
    for (int i = 0 ; i < self.titleViewArray.count; i++){
        LXCarSellListViewController *vc = [self viewControllerIndex:i];
        [self.viewControllers addObject:vc];
    }
    self.PageControlView = [[YJPageControlView alloc] initWithFrame:frame Titles:self.titleViewArray viewControllers:self.viewControllers Selectindex:self.selectIndex];
    self.PageControlView.delegate = self;
   [self.PageControlView showInViewController:self];
}
- (LXCarSellListViewController *)viewControllerIndex:(NSInteger)index {
    LXCarSellListViewController *vc = [[LXCarSellListViewController alloc] init];
    switch (index){
        case 0:
        {
            vc.selectIndex = 11; //全部
        }
        break;
        case 1:
        {
            vc.selectIndex = 6;// 已出售
        }
        break;
        case 2:
        {
            vc.selectIndex = 5;// 出售中
        }
        break;
        case 3:
        {
            vc.selectIndex = 4; // 未出售
        }
        break;
        default:
        break;
    }
    return vc;
}

- (void)SelectAtIndex:(NSInteger)index{
    self.PageControlView.selectedIndex = index;
    
    
    self.searchView.textField.text = @"";
    self.searchView.textField.text = nil;
    
}

@end
